import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/formatter.dart';
import 'package:flutterproject/page/mine/children/assets/childdren/transform/controller/transform_controller.dart';
import 'package:flutterproject/page/mine/children/assets/controller/my_assets_controller.dart';
import 'package:flutterproject/util/dialog_toast/dialog_util.dart';
import 'package:flutterproject/util/extension/int_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/button_common.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:flutterproject/widget/text/text_field_common.dart';
import 'package:get/get.dart';

class TransformPage extends BaseState<TransformController> {
  final String title;
  final double amount;
  final bool showTips;
  final String pageTitle;

  TransformPage(this.title, this.amount, this.showTips, this.pageTitle);

  @override
  TransformController initController() => TransformController();

  @override
  Widget initView(BuildContext context) {
    return ColoredBox(
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          AppBarCommon(
            title: title,
            bgColor: Color(0xFFEDC88B),
            leftColor: Colors.white,
            titleColor: Colors.white,
          ),
          Container(
            margin: MarginPaddingUtil.only(top: 78, left: 40, right: 40),
            padding: MarginPaddingUtil.fromLTRB(
                left: 30, top: 47, right: 30, bottom: 61),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.radius),
            ),
            child: Column(
              children: [
                Row(
                  children: [
                    TextCommon(
                      title,
                      size: 28.sp,
                      fontWeight: FontWeight.bold,
                      color: Color(0xFFEDC88B),
                    ),
                    62.widthBox,
                    TextCommon(
                      "$amount",
                      size: 28.sp,
                      fontWeight: FontWeight.bold,
                      color: Color(0xFFEDC88B),
                    )
                  ],
                ),
                30.heightBox,
                _buildBg(
                  child: TextCommon(
                    "手机号",
                    size: 28.sp,
                    color: Color(0xFF707070),
                  ),
                  textEditingController: controller.phoneController,
                ),
                66.heightBox,
                _buildBg(
                    child: TextCommon(
                      "输入转出额度",
                      size: 28.sp,
                      color: Color(0xFF707070),
                    ),
                    textEditingController: controller.moneyController,
                    inputFormatters: [InputFormatter()]),
                66.heightBox,
                ButtonCommon(
                  text: "确定转出",
                  onTap: () => showPwdDialog(),
                  width: 472.width,
                  color: Color(0xFFEDC88B),
                  borderRadios: 30.radius,
                  fontColor: Colors.white,
                  fontSize: 36.sp,
                  fontWeight: FontWeight.bold,
                  padding: MarginPaddingUtil.symmetric(vertical: 20),
                ),
              ],
            ),
          ),
          30.heightBox,
          if (showTips)
            Row(
              children: [
                43.widthBox,
                ImageCommon(
                  "/icon/ic_notic",
                  size: 30.width,
                ),
                23.widthBox,
                TextCommon(
                  "仅限主账号子账号之间划转",
                  color: Color(0xFF707070),
                  size: 24.sp,
                  lineHeight: 35.sp,
                )
              ],
            )
        ],
      ),
    );
  }

  Widget _buildBg({
    required Widget child,
    required TextEditingController textEditingController,
    List<TextInputFormatter>? inputFormatters,
  }) {
    return Container(
      width: Get.width,
      padding: MarginPaddingUtil.symmetric(vertical: 24, horizontal: 40),
      decoration: BoxDecoration(
        color: Color(0xFFF6F6F6),
        borderRadius: BorderRadius.circular(32.radius),
      ),
      child: Row(
        children: [
          child,
          Expanded(
              child: TextFieldCommon(
            align: TextAlign.right,
            controller: textEditingController,
            height: 72.width,
            size: 50.sp,
            textColor: Colors.black,
            padding: MarginPaddingUtil.symmetric(horizontal: 25),
            inputFormatters: inputFormatters,
            keyboardType: TextInputType.number,
          ))
        ],
      ),
    );
  }

  void showPwdDialog() {
    DialogUtil.showPwdDialog((value) {
      Get.find<MyAssetsController>().transform(
        mobile: controller.phoneController.text,
        pwd: value,
        money: controller.moneyController.text,
      );
    });
  }
}
